package net.eearley.getco.app.base;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * The Class KeypadGamePiece.
 */
public abstract class KeypadGamePiece {

	/** The keypad. */
	protected Keypad keypad;

	/** The current key. */
	protected Key currentKey;

	/**
	 * Gets the current key.
	 * 
	 * @return the current key
	 */
	public Key getCurrentKey() {
		return currentKey;
	}

	/** The allkeys. */
	protected List<Key> allkeys = new ArrayList<Key>();

	/**
	 * Instantiates a new keypad game piece.
	 * 
	 * @param key
	 *            the key
	 * @param keypad
	 *            the keypad
	 */
	public KeypadGamePiece(Keypad keypad, Key key) {
		this.keypad = keypad;
		this.currentKey = key;
		setPossibleMoves(key);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return this.keypad.getLabel(currentKey) + "--" + currentKey.toString();
	}

	/**
	 * Sets the possible moves.
	 * 
	 * @param key
	 *            the new possible moves
	 */
	abstract public void setPossibleMoves(Key key);

	/**
	 * Gets the coords.
	 * 
	 * @return the coords
	 */
	public int[][] getCoords() {
		return currentKey.getCoords();
	}

	/**
	 * Gets the keypad.
	 * 
	 * @return the keypad
	 */
	public Keypad getKeypad() {
		return keypad;
	}

	public List<Key> getTotalValidKeys() {
		List<Key> allValidKeys = new ArrayList<Key>();
		for (Key possiblekey : allkeys) {
			if (keypad.isValid(possiblekey.getCoords())) {
				allValidKeys.add(possiblekey);
			}
		}
		return allValidKeys;
	}

	/**
	 * Gets the total moves.
	 * 
	 * @return the total moves
	 */
	public int getTotalMoves() {
		int counter = 0;
		for (Key possiblekey : allkeys) {
			if (keypad.isValid(possiblekey.getCoords())) {
				counter++;
			}
		}
		return counter;
	}

	/**
	 * Gets the x coord.
	 * 
	 * @return the x coord
	 */
	public int getXCoord() {
		return currentKey.getXCoord();
	}

	/**
	 * Gets the y coord.
	 * 
	 * @return the y coord
	 */
	public int getYCoord() {
		return currentKey.getYCoord();
	}

	/**
	 * Sets the keypad.
	 * 
	 * @param keypad
	 *            the new keypad
	 */
	public void setKeypad(Keypad keypad) {
		this.keypad = keypad;
	}

	/**
	 * Recursive button push.
	 * 
	 * @param allkeys2
	 *            the keys
	 * @param counter
	 *            the counter
	 * @param keypadGamePiece
	 *            the keypad game piece
	 * @param sequenceLength
	 *            the sequence length
	 * @param vowelLimit
	 *            the vowel limit
	 * 
	 * @return the int
	 */
	abstract public int recursiveButtonPush(int sequenceLength,
			Map<String, List<Key>> allkeys, AtomicInteger counter,
			KeypadGamePiece keypadGamePiece, int vowelLimit);

}